const { contextBridge, ipcRenderer } = require('electron');

// 暴露API给渲染进程
contextBridge.exposeInMainWorld('electronAPI', {
  // 微信服务管理
  startWechatService: () => ipcRenderer.invoke('start-wechat-service'),
  stopWechatService: () => ipcRenderer.invoke('stop-wechat-service'),
  checkWechatService: () => ipcRenderer.invoke('check-wechat-service'),
  
  // 微信API调用
  getWechatApi: (endpoint, params) => ipcRenderer.invoke('get-wechat-api', endpoint, params),
  postWechatApi: (endpoint, data) => ipcRenderer.invoke('post-wechat-api', endpoint, data),
  
  // 事件监听
  onWechatLog: (callback) => ipcRenderer.on('wechat-log', (_, value) => callback(value)),
  onWechatError: (callback) => ipcRenderer.on('wechat-error', (_, value) => callback(value)),
  onWechatStatus: (callback) => ipcRenderer.on('wechat-status', (_, value) => callback(value)),
  
  // 移除事件监听
  removeAllListeners: () => {
    ipcRenderer.removeAllListeners('wechat-log');
    ipcRenderer.removeAllListeners('wechat-error');
    ipcRenderer.removeAllListeners('wechat-status');
  }
}); 